﻿using System;
using System.Diagnostics;
using Lucene.Net.Documents;

namespace LuceneApiServer
{
    /// <summary>
    ///     表示要匹配的字段
    /// </summary>
    [Serializable]
    [DebuggerDisplay("Name ={Name}")]
    public class LnMatchField
    {
        /// <summary>
        ///     字段名小写
        /// </summary>
        private string _name;

        /// <summary>
        ///     获取或设置字段名
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value.ToLower(); }
        }

        /// <summary>
        ///     分词索引
        /// </summary>
        public Field.Index Index { get; set; }

        /// <summary>
        ///     是否条件过滤，true时附加匹配搜索
        /// </summary>
        public bool IsTerm { get; set; }

        /// <summary>
        ///     条件关键字，IsTerm=true，TermKeyword！=null 时有效，条件过滤
        /// </summary>
        public string TermKeyword { get; set; }

        /// <summary>
        ///     获取或设置摘要段的字符数
        ///     0为全部
        /// </summary>
        public int FragmentSize { get; set; }

        /// <summary>
        ///     获取或设置关键字前缀
        /// </summary>
        public string KeywordPrefix { get; set; }

        /// <summary>
        ///     获取或设置关键字后缀
        /// </summary>
        public string KeywordSuffix { get; set; }

        /// <summary>
        ///     是否可以设置高亮
        /// </summary>
        /// <returns></returns>
        public bool CanSetHighLight()
        {
            return FragmentSize > 0 || !string.IsNullOrEmpty(KeywordSuffix) || !string.IsNullOrEmpty(KeywordPrefix);
        }
    }
}